package com.sf.fy.uav.applet.shop.controller;

import com.sf.fy.uav.applet.shop.service.IShoppingService;
import com.sf.fy.uav.common.response.order.CommodityDetailInfoResponse;
import com.sf.fy.uav.common.response.shopping.CommodityDetailResponse;
import com.sf.fy.uav.common.response.shopping.ShoppingDataResponse;
import com.sf.fy.uav.common.utils.Rs;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author 01430312
 */
@RestController
@RequestMapping("/home/shopping/")
public class ShoppingController {


    @Autowired
    private IShoppingService iShoppingService;

    @GetMapping("get-shopping-data")
    @Operation(tags = "获取商品主页信息", description = "获取商品主页信息")
    public Rs<ShoppingDataResponse> getShoppingData(@RequestParam(required = false) String placementPointId,
                                                    @RequestParam(required = false) BigDecimal longitude,
                                                    @RequestParam(required = false) BigDecimal latitude) {

        return Rs.success(iShoppingService.getShoppingData(placementPointId, longitude, latitude));
    }

    @GetMapping("check-distance")
    @Operation(tags = "判断是否在范围内,true表示过远不在范围内", description = "判断是否在范围内,true表示过远不在范围内")
    public Rs<Boolean> checkDistance(@RequestParam() String placementPointId,
                                     @RequestParam() BigDecimal longitude,
                                     @RequestParam() BigDecimal latitude) {

        return Rs.success(iShoppingService.checkDistance(placementPointId, longitude, latitude));
    }

    @GetMapping("get-commodity-detail")
    @Operation(tags = "获取商品详情", description = "获取商品详情")
    public Rs<CommodityDetailResponse> getCommodityDetail(@RequestParam String commodityId) {
        return Rs.success(iShoppingService.getCommodityDetail(commodityId));
    }

    @GetMapping("get-order-detail-by-order-id")
    @Operation(tags = "获取订单详情", description = "获取订单详情")
    public Rs<CommodityDetailInfoResponse> getOrderDetailByOrderId(@RequestParam String orderId) {
        return Rs.success(iShoppingService.getOrderDetailByOrderId(orderId));
    }
}
